﻿using System;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Linq;
using System.Runtime.Serialization;

namespace TraceView.Shared
{
    [DataContract(IsReference = true)]
    public sealed class DataItem
    {
        [DataMember]
        private readonly string _key;

        [DataMember]
        private readonly string _value;

        public DataItem(string key, string value)
        {
            this._key = key;
            this._value = value;
        }

        public string Key
        {
            get { return this._key; }
        }

        public string Value
        {
            get { return this._value; }
        }
    }

    public class DataItems : KeyedCollection<string, DataItem>
    {
        protected override string GetKeyForItem(DataItem item)
        {
            return item.Key;
        }
    }

    [DataContract(IsReference = true)]
    public sealed class TraceData
    {
        [DataMember]
        private readonly StringCollection _categories = new StringCollection();

        public StringCollection Categories
        {
            get { return _categories; }
        }

        [DataMember]
        public Severity Severity { get; set; }

        [DataMember]
        public string Source { get; set; }

        [DataMember]
        public string UserName { get; set; }

        [DataMember]
        public DateTime TimeStamp { get; set; }

        [DataMember]
        public string ApplicationName { get; set; }

        [DataMember]
        public TraceObject TraceObject { get; set; }
    }

    [DataContract]
    public class TraceObject
    {
        [DataMember] private readonly DataItems _dataItems;
        [DataMember] private readonly string _type;

        public TraceObject(string type)
        {
            _type = type;
            _dataItems = new DataItems();
        }

        public string Type
        {
            get { return _type; }
        }

        public DataItems DataItems
        {
            get { return _dataItems; }
        }
    }

    public enum Severity
    {
        Information = 1,
        Verbose = 2,
        Warning = 3,
        Error = 4,
        Critical = 5
    }
}